package com.it.iostream.Utils;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/*
 * @Jiang:读取配置文件
 * */

public class ReadProperties {


    public static String readsomething(String filename) {
        Properties properties = new Properties();
        try {
            FileInputStream in = new FileInputStream("src/main/resources/application.properties");
            BufferedReader aa= new BufferedReader(new InputStreamReader(in,"UTF-8"));
            properties.load(aa);  //将配置信息加载到properties对象中
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        HashMap<Object,Object> hm = new HashMap<>();
        for (Map.Entry<Object, Object> item : properties.entrySet()) {  //遍历输出从配置文件中读取的信息
               //不存在就添加，存在就覆盖
                hm.put(item.getKey(),item.getValue());
        }
        String bacpack = "";
        for (Object readnow: hm.keySet()) {
            //不能用 ==  ==是比较values和hash值   要用equals
            if(readnow.toString().equals(Suffix.getSuffix (filename))){
                   bacpack = hm.get(readnow).toString();
                   break;
            }
        }

        return bacpack;
    }


}
